package com.ruoyi.web.test;

import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpUtil;

import java.util.HashMap;
import java.util.Map;

/**
 * 阿里云定位：最高精度（山东省聊城市东昌府区黑龙江路辅路）
 */
public class Dw {
    public static void main(String[] args) {
        String host = "https://ipcxzyb.market.alicloudapi.com";
        String path = "/ipQuery";
        String appcode = "58399bbc82a547b18159f99511e19f28";
        Map<String, String> headers = new HashMap<String, String>();
        //最后在header中的格式(中间是英文空格)为Authorization:APPCODE 83359fd73fe94948385f570e3c139105
        headers.put("Authorization", "APPCODE " + appcode);
        Map<String, Object> querys = new HashMap<String, Object>();
        querys.put("ip", "58.58.239.106");


        try {
            /**
             * 重要提示如下:
             * HttpUtils请从
             * https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/src/main/java/com/aliyun/api/gateway/demo/util/HttpUtils.java
             * 下载
             *
             * 相应的依赖请参照
             * https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/pom.xml
             */
            //HttpResponse response = HttpUtils.doGet(host, path, method, headers, querys);
            String body = HttpUtil.createGet(host+path).addHeaders(headers).form(querys).execute().body();
            System.out.println(body);
//            JSONObject jsonObject = JSONObject.parseObject(body);
//            String string = JSONObject.parseObject(jsonObject.getString("showapi_res_body")).getString("multiAreas");
//            String lat = JSONObject.parseObject(string).getString("lat");
//            String lng = JSONObject.parseObject(string).getString("lng");
//            GlobalCoordinates source = new GlobalCoordinates(29.490295, 106.486654);
//            GlobalCoordinates target = new GlobalCoordinates(Double.parseDouble(lat), Double.parseDouble(lng));
//            double distanceMeter = CaculateDistanceTest.getDistanceMeter(source, target, Ellipsoid.Sphere);
//            System.out.println(distanceMeter);
            //获取response的body
            //System.out.println(EntityUtils.toString(response.getEntity()));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
